<template>
	<view class="content">
		<view class="header">
			<u-sticky bgColor="#fff">
				<u-tabs :list="list1" @click="qiehuan()"></u-tabs>
			</u-sticky>
		</view>
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="item.id" @click="to(item.id)" v-if="list.length > 0">
				<view class="info">
					<view class="title font24 fontw">
						#{{item.title}}
					</view>
					<!-- <view class="des font18" v-html="item.text">
					</view> -->
					<view class="icon" @click.stop="popShow(item)">
						<image src="https://wx.caobenjiankang.com/image/technicianadd/share.png" mode="aspectFit"></image>
					</view>
				</view>
				<view class="image">
					<image :src="item.image" mode="aspectFit"></image>
				</view>
			</view>
			<view class="tips font32 fontw" v-else>
				暂无数据
			</view>
		</view>
		<clh-popup :position="position" v-model="showPopup" :canSlide="false">
			<view class="popup">
				<view class="title font28 fontw">
					分享设置
				</view>
				<view class="des font22">
					分享成功后自动上传
				</view>
				<view class="left">
					<view class="describe font28 fontw">
						文章名称
					</view>
					<view class="container font26">
						{{text.title}}
					</view>
				</view>
				<!-- <view class="left">
					<view class="describe font28 fontw">
						分享作者
					</view>
					<view class="container font26">
						小乔
					</view>
				</view> -->
				<view class="text">
					<view class="describe font28 fontw">
						分享心得
					</view>
					<view class="uni-textarea">
						<textarea @blur="bindTextAreaBlur" maxlength="20" :auto-height="true" placeholder="输入本次分享心得"
							placeholder-style="font-size: 18rpx;color: #666666;" :editable="false" :disabled="false" />
					</view>
				</view>
				<button class="list_bt_sm" style="border-right:none;" open-type="share">
				<view class="btn font28">
					分享
				</view>
				</button>
				<!-- <button open-type="share" class="clear-btn show-item flex-center f-paragraph text-bold"
					style="margin-top: 20rpx;border-radius: 16rpx;">分享</button> -->
			</view>
		</clh-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				position: 'bottom',
				showPopup: false,
				summary: '',
				list: [],
				list1:[],
				text: {},
				info: {
					page: 1,
					cate_id: 0
				},
				total: 1,
				userInfo: {},
			};
		},
		onLoad() {
			this.getinfocate()
			this.getuserInfo()
		},

		onReachBottom() {
			if (this.info.page >= this.total) {
				uni.showToast({
					icon: 'error',
					title: '暂无更多',
					duration: 1000
				})
			} else {
				this.info.page = this.info.page + 1
				this.getData()
			}
		},
		onShareAppMessage() {
			let path = '/technicianadd/pages/text/text?id=' + this.text.id+ '&pid=' + this.userInfo.id
			return {
				title: this.text.title,
				path: path,
				imageUrl: this.text.image,
			}
		},
		methods: {
			async getuserInfo() {
				var res = await this.$api.mine.index()
				this.userInfo = res
			},
			async getinfocate() {
				this.$util.showLoading()
				var info = await this.$api.zxcadd.articleCate();
				const list = []
				info.map(item => {
					list.push({
						id: item.id,
						name: item.title
					})
				})
				this.list1 = list
				this.info.cate_id = list[0].id
				this.getData()
				this.$util.hideAll()
			},
			async getData() {
				var data = await this.$api.zxcadd.articleList(this.info);
				this.total = data.last_page
				if (data.data.length > 0) {
					this.list = [...this.list, ...data.data]
				}
			},
			popShow(item) {
				this.showPopup = true
				this.text = item
				this.summary = ''
			},
			bindTextAreaBlur(e) {
				this.summary = e.detail.value
			},
			
			to(id) {
				uni.navigateTo({
					url: '/technicianadd/pages/text/text?id=' + id
				})
			},
			qiehuan(e){
				this.info.cate_id = e.id
				this.list = []
				this.getData()
			}
			
		}
	}
</script>

<style lang="scss">
	.content {
		

		.list {
			padding: 36rpx 34rpx;
			.item {
				display: flex;
				align-items: center;
				margin-bottom: 18rpx;
				background-color: #fff;
				border-radius: 21rpx;
				padding: 21rpx 33rpx;

				.info {
					flex: 1;

					.title {
						margin-bottom: 15rpx;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						/* 定义显示的行数 */
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.des {
						color: #666666;
						margin-bottom: 15rpx;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						/* 定义显示的行数 */
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.icon {
						width: 31rpx;
						height: 31rpx;
						display: flex;
						align-items: center;

						image {
							width: 31rpx;
							height: 31rpx;
						}
					}
				}

				.image {
					width: 104rpx;
					height: 104rpx;
					background: #1EB481;
					border-radius: 11rpx;
					overflow: hidden;
					margin-left: 16rpx;

					image {
						width: 104rpx;
						height: 104rpx;
					}
				}
			}
		}

		.popup {
			padding: 27rpx 40rpx;

			.title {
				margin-bottom: 21rpx;
			}

			.des {
				margin-bottom: 61rpx;
			}

			.left {
				justify-content: space-between;
				margin-bottom: 21rpx;

				.describe {
					width: 140rpx;
				}

				.container {
					color: #666666;
					flex: 1;
					text-align: end;
				}
			}

			.text {
				display: flex;
				flex-direction: column;
				margin-bottom: 55rpx;

				.describe {
					margin-bottom: 21rpx;
				}

				.uni-textarea {
					min-height: 181rpx;
					background: #7E7E7E30;
					border-radius: 20rpx;
					padding: 27rpx 24rpx;
				}
			}

			.btn {
				height: 80rpx;
				background: linear-gradient(0deg, #24B682 0%, #97DD97 100%);
				border-radius: 100rpx;
				color: #FFFFFF;
				text-align: center;
				line-height: 80rpx;
			}
		}
	}

	.tips {
		text-align: center;
		color: #969696;
	}
</style>